package de.tempel.fittslaw.objects;

public class Trial {

	private int xPositionOfLeftTarget;
	private int distanceBetweenTargets;
	private int widthOfTargets;
	private int clickCount;
	private int missedCount;
	private long startTime;
	private long length = 10000;

	public Trial(int xPositionOfLeftTarget, int distanceBetweenTargets,
			int widthOfTargets) {
		this(xPositionOfLeftTarget, distanceBetweenTargets, widthOfTargets, 0);

	}

	public Trial(int xPositionOfLeftTarget, int distanceBetweenTargets,
			int widthOfTargets, int clickCount) {
		this.xPositionOfLeftTarget = xPositionOfLeftTarget;
		this.distanceBetweenTargets = distanceBetweenTargets;
		this.widthOfTargets = widthOfTargets;
		this.clickCount = clickCount;
	}

	public void start() {
		setClickCount(0);
		setMissedCount(0);
		startTime = System.currentTimeMillis();
	}

	public boolean isFinished() {
		if (System.currentTimeMillis() - startTime > length) {
			return true;
		}
		return false;
	}

	public long runningTime() {
		return System.currentTimeMillis() - startTime;
	}

	public void targetMissed() {
		missedCount++;
	}

	public void targetHit() {
		clickCount++;
	}

	public double getMovementTime() {
		return (double) this.length / this.clickCount / 1000;
	}

	public double getIndexOfDifficulty() {
		return (double) Math.log(2 * getDistanceBetweenTargets()
				/ widthOfTargets)
				/ Math.log(2.0);
	}

	public int getMissedCount() {
		return missedCount;
	}

	public void setMissedCount(int missedCount) {
		this.missedCount = missedCount;
	}

	public long getLenght() {
		return length;
	}

	public void setLength(long length) {
		this.length = length;
	}

	public long getStartTime() {
		return startTime;
	}

	public void setStartTime(long startTime) {
		this.startTime = startTime;
	}

	public int getxPositionOfLeftTarget() {
		return xPositionOfLeftTarget;
	}

	public void setxPositionOfLeftTarget(int xPositionOfLeftTarget) {
		this.xPositionOfLeftTarget = xPositionOfLeftTarget;
	}

	public int getDistanceBetweenTargets() {
		return distanceBetweenTargets;
	}

	public void setDistanceBetweenTargets(int distanceBetweenTargets) {
		this.distanceBetweenTargets = distanceBetweenTargets;
	}

	public int getWidthOfTargets() {
		return widthOfTargets;
	}

	public void setWidthOfTargets(int widthOfTargets) {
		this.widthOfTargets = widthOfTargets;
	}

	public int getClickCount() {
		return clickCount;
	}

	public void setClickCount(int clickCount) {
		this.clickCount = clickCount;
	}

	@Override
	public String toString() {
		return "Trial [distanceBetweenTargets=" + distanceBetweenTargets
				+ ", widthOfTargets=" + widthOfTargets + ", clickCount="
				+ clickCount + ", missedCount=" + missedCount + ", startTime="
				+ startTime + ", length=" + length + ", getMovementTime()="
				+ getMovementTime() + ", getIndexOfDifficultiy()="
				+ getIndexOfDifficulty() + "]";
	}

}